<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./../baseAdm.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns="http://www.w3.org/1999/xhtml">
    
    <ui:define name="content">
        <h:form id="form">


            <p:ajaxStatus style="width:16px;height:16px;">
                <f:facet name="start">
                    <h:graphicImage name="ajaxloading.gif" library="images" />
                </f:facet>

                <f:facet name="complete">
                    <h:outputText value="" />
                </f:facet>
            </p:ajaxStatus>
            <p:dataTable id="tabCliente" var="varCliente" value="#{clienteFace.lista}" selectionMode="single">

                <f:facet name="header" >Clientes Cadastrados
                </f:facet>

                <p:column sortBy="#{varCliente.id}">
                    <f:facet name="header"><h:outputText value="Id"/></f:facet>
                    <h:outputText value="#{varCliente.id}"/>
                </p:column>

                <p:column  sortBy="#{varCliente.nickName}">
                    <f:facet name="header">Nick Name</f:facet>
                    <h:outputText value="#{varCliente.nickName}"/>
                </p:column>

                <p:column  sortBy="#{varCliente.nome}">
                    <f:facet name="header">Nome/Razão Social</f:facet>
                    <h:outputText value="#{varCliente.nome}"/>
                </p:column>

                <p:column  sortBy="#{varCliente.cidade}">
                    <f:facet name="header">Cidade</f:facet>
                    <h:outputText value="#{varCliente.cidade}"/>
                </p:column>

                <p:column  sortBy="#{varCliente.email}">
                    <f:facet name="header">Email</f:facet>
                    <h:outputText value="#{varCliente.email}" >
                        
                    </h:outputText>
                </p:column>

                <p:column>
                    <f:facet name="header">Ações</f:facet>
                    
                    <p:commandLink  value="Contrato" 
                                    action="/login/administracao/cadastros/cadContrato.faces?faces-redirect=true&amp;includeViewParams=true"
                                      immediate="true" title="Contrato" >
                        <f:setPropertyActionListener value="#{varCliente}" target="#{contratoFace.selectedCliente}" />-
                        <!--<f:param name="cliente" value="#{varCliente}"/>-->
                    </p:commandLink>
                    
                    <p:commandButton image="ui-icon-pencil" update=":form:painel"
                                     oncomplete="conceDialog.show()" title="Editar" >
                        <f:setPropertyActionListener value="#{varCliente}" target="#{clienteFace.selectedBean}" />
                    </p:commandButton>

                    <p:commandButton image="ui-icon-trash" update="painel"
                                     title="Excluir" oncomplete="confirmation.show()" >
                        <f:setPropertyActionListener value="#{varCliente}"  target="#{clienteFace.selectedBean}" />
                    </p:commandButton>
                    
                </p:column>
                <f:facet name="footer">
                    <p:commandButton image="ui-icon-disk" update=":form:painel"
                                     title="Novo" value="Novo" oncomplete="conceDialog.show()"
                                     action="#{clienteFace.doCreate}"/>
                </f:facet>
            </p:dataTable>

            <p:dialog widgetVar="conceDialog" width="650" resizable="true" modal="true"
                      id="conceDlg" header="Cadastro de tabClientesionárias" showEffect="explode"
                      hideEffect="slide">
                <p:outputPanel id="painel" rendered="true" >
                    <script type="text/javascript">
                        (function($){
                            $(function(){
                                $('input:text').setMask();
                            });
                        })(jQuery);

                    </script>
                    <h:panelGrid columns="2"  >
                        <h:outputLabel value="Nome:"/>
                        <p:inputText id="iNome" value="#{clienteFace.selectedBean.nome}" rendered="true" size="50" />
                        
                        <h:selectOneMenu id="tipoPessoa"  value="#{clienteFace.docMask}"    immediate="true"  >
                            <f:selectItem itemLabel="Pessoa Jurídica" itemValue="cnpj"   />
                            <f:selectItem itemLabel="Pessoa Física" itemValue="cpf" />
                            
                            <p:ajax event="change" update="painelPFPJ" immediate="true" /> 
                        </h:selectOneMenu>
                        <p:outputPanel id="painelPFPJ">
                            <script type="text/javascript">
                                (function($){
                                    $(function(){
                                        $('input:text').setMask();
                                    });
                                })(jQuery);

                            </script>
                            <p:inputText title="CPF/CNPJ" id="docPFPJ"
                                         value="#{clienteFace.selectedBean.cnpj}" alt="#{clienteFace.docMask}"/>
                        </p:outputPanel>
                        
                        <h:outputLabel value="Tipo end.:"/>
                        <h:selectOneMenu value="#{clienteFace.selectedBean.tipoende}">
                            <f:selectItems value="#{clienteFace.listaLograd}"  
                                           var="cbL" itemValue="#{cbL.value}" itemLabel="#{cbL.label}"  />
                        </h:selectOneMenu> 
                        <h:outputLabel value="Logradouro:"/>
                        <p:inputText id="iLograd" value="#{clienteFace.selectedBean.ende}"/>
                        <h:outputLabel value="Num.:"/>
                        <p:inputText value="#{clienteFace.selectedBean.num}"/>
                        <h:outputLabel value="Complemento:"/>
                        <p:inputText value="#{clienteFace.selectedBean.compl}"/>
                        
                        <h:outputLabel value="Bairro:"/>
                        <p:inputText value="#{clienteFace.selectedBean.bairro}"/>
                        <h:outputLabel value="CEP:"/>
                        <p:inputText value="#{clienteFace.selectedBean.cep}" alt="cep" rendered="true">
                            <f:converter converterId="cepConverter"/>
                        </p:inputText>
                        <h:outputLabel value="Cidade:"/>
                        <p:inputText value="#{clienteFace.selectedBean.cidade}"/>
                        
                        <h:outputLabel value="UF:"/>
                        <h:selectOneMenu  value="#{clienteFace.selectedBean.uf}">
                            <f:selectItems value="#{clienteFace.listaUF}"  
                                           var="cbUF" itemValue="#{cbUF.value}" itemLabel="#{cbUF.label}"  />
                        </h:selectOneMenu>
                        
                        <h:outputLabel value="Fone:"/>
                        <p:inputText value="#{clienteFace.selectedBean.fone}" alt="phone"/>
                        
                        <h:outputLabel value="Fax:"/>
                        <p:inputText value="#{clienteFace.selectedBean.fax}" alt="phone"/>
                        
                        <h:outputLabel value="Email:"/>
                        <p:inputText value="#{clienteFace.selectedBean.email}" > 
                            
                        </p:inputText>
                        <h:outputLabel value="Nick Name:"/>
                        <p:inputText value="#{clienteFace.selectedBean.nickName}"/>
                        
                        <h:outputLabel value="Cod. Concessionária:"/>
                        <p:inputText value="#{clienteFace.selectedBean.nuc}" alt="number"/>                        
                            
                        <p:commandButton value="Salvar" action="#{clienteFace.doSave()}"
                                         oncomplete="conceDialog.hide()" update="tabCliente">

                        </p:commandButton>
                        <p:commandButton value="Cancelar" oncomplete="conceDialog.hide()" action="#{clienteFace.resetIsNew}"/>
                    </h:panelGrid>

                </p:outputPanel>
            </p:dialog>

            <p:confirmDialog message="Você deseja realmente exluir este registro?" width="200"
                             showEffect="explode" hideEffect="explode"
                             header="Confirmação" severity="alert" widgetVar="confirmation" modal="true">

                <p:commandButton value="Sim" update="tabCliente" action="#{clienteFace.doRemove}"
                                 oncomplete="confirmation.hide()"/>
                <p:commandButton value="Não" onclick="confirmation.hide()" type="button" />

            </p:confirmDialog>
        </h:form>

    </ui:define>

</ui:composition>